package com.sh.apigateway.config;

import com.sh.apigateway.filter.InterfaceInvokeFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Component
public class GatewayConfig {


    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder, InterfaceInvokeFilter filter) {
        //用路由前缀区分路由来源是前端还是接口管理平台
        return builder.routes()
                .route(r ->
                        r.path("/interface/**")
                        .filters(f -> f.filter(filter))
                                .uri("lb://shApi-interface")
                )
                .build();
    }



}
